/**	\author    coidgen 0.9.2
	\version    (12.1 build 28)
	\date      
	\brief     
*/

#ifndef __COID_CLIENT__tunnelmgr_h
#define __COID_CLIENT__tunnelmgr_h


#define CLIENT__tunnelmgr_h



#include "coid/coidclient.h"
#include "coid/comm/sync/mutex_reg.h"


extern const version COID_version_TunnelMgr_12_1;





namespace coid {


struct COID_TABLE_TunnelMgr_12_1;


///COID http tunneling gateway
class TunnelMgr_client
{
	//NET_OPTIONS: nolog nolog_system_calls direct interprocess
private:
	COID_TABLE_TunnelMgr_12_1 * _me;
	COID_TABLE_TunnelMgr_12_1 * _vtbl;
	mutable comm_mutex_custom_reg<netstream, void*> _mx_reg;
	uint _conn_data;
	uint _timeout;
	charstr _addr;

	void set_connection_type( uint ct ) {_conn_data = ct;}
	void destroy_me();

public:
	TunnelMgr_client();
	~TunnelMgr_client();
	TunnelMgr_client( const TunnelMgr_client & c );
	TunnelMgr_client & operator = ( const TunnelMgr_client & c );

	opcd ping_server( const char * coid_address, uint coid_obj_id=UMAX32, uint coid_flags=ConnectFlags::xACCESS_MODE ) const;
	bool is_connected() const;
	opcd disconnect();
	const charstr& get_addr() const {return _addr;}
	comm_mutex_reg * get_mx() {return &_mx_reg;}
	opcd get_last_error() const;
	void set_last_error( opcd e );
	uint get_connection_type() const {return _conn_data;}
	opcd set_timeout( uint milliseconds );
	uint get_timeout() const {return _timeout;}
	void setup_stream( binstream& b, uint coid_flags, uint coid_obj_id ) const;
	bool setup_members( uint coid_stream_flags, netstream * bstream, binstream * bstream2=NULL, comm_mutex_reg * mx_reg=NULL );

	static const version & get_version() { return COID_version_TunnelMgr_12_1; }


public:
	// special functions
	opcd connect(   const char * coid_address=NULL, uint coid_flags=ConnectFlags::xACCESS_MODE  );
	// special functions
	opcd connect_within(  comm_mutex_reg & coid_channel );
	opcd connect_shared( uint coid_obj_id, const char * coid_address=NULL, uint coid_flags=ConnectFlags::xACCESS_MODE );

	///Process incomming tunnel requests
	opcd process_tunnel( httpstreamcoid::header & hdr, cachestream & net, netAddress & addr );
	///Process incomming http call requests
	opcd process_local_call( httpstreamcoid & net, token qry, netAddress & addr );
	///Process remote...
	opcd process_remote_call(dynarray<uchar> & buf, const charstr & qry, netAddress & addr, uint64 & ssid, charstr & contentType);
	///Process remote soap call...
	opcd process_remote_soap_call(dynarray<uchar> & buf, charstr & service, netAddress & addr, uint64 & ssid);
	///Process loacl soap call...
	opcd process_local_soap_call(httpstreamcoid & net, charstr & service, netAddress & addr, uint64 & ssid);
};

} // namespace coid


#endif	// ! __COID_CLIENT__tunnelmgr_h
